home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / CodeTextView.h < prev    next >
C/C++ Source or Header  |  1992-04-27  |  3KB  |  117 lines

  1. #ifndef CodeTextView_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define CodeTextView_First
  7.  
  8. #include "TextView.h"
  9. #include "TextFormatter.h"
  10.  
  11. //---- CodeTextView --------------------------------------------------------
  12. // a TextView for editing programm text
  13. // adds: auto indenting
  14. //       highlighting matching brackets
  15. //       (double clicking on a bracket selects the text enclosed by the brackets)
  16.  
  17. class CharStyle;
  18.  
  19. class CodeTextView: public TextView {
  20. public:
  21.     MetaDef(CodeTextView);
  22.  
  23.     CodeTextView(
  24.     EvtHandler *eh, Rectangle r, Text *t, 
  25.     bool wrap= TRUE,
  26.     TextViewFlags= eTextViewDefault, 
  27.     Point border= gBorder, 
  28.     TViewAlign m= eTViewLeft,
  29.     int id= cIdNone
  30.     ); // for efficency reasons do not set contentRect.extent.x to cFit
  31.  
  32.     //---- formatting of source code
  33.     virtual class PrettyPrinter *MakePrettyPrinter(
  34.     Text *t, CharStyle *cs, CharStyle *fs, CharStyle *cds, CharStyle *ps
  35.     );
  36.     void FormatCode();
  37.     void SetDefaultStyle();
  38.     void SetFont(Font *fp);
  39.     
  40.     //---- controller methods 
  41.     Command *DoLeftButtonDownCommand(Point, Token, int); // matching brackets
  42.     Command *DoKeyCommand(int, Token);      // auto indent
  43.     Command *DoMenuCommand(int);
  44.     Command *DoOtherEventCommand(Point p, Token t);
  45.     Command *DoCursorKeyCommand(EvtCursorDir, Token);    
  46.     void SetAutoIndent(bool);
  47.     bool GetAutoIndent();
  48.     
  49. protected:
  50.     bool autoIndent;
  51.     Point cursorPos;
  52.     CharStyle *commentStyle;
  53.     CharStyle *functionStyle;
  54.     CharStyle *classDeclStyle;
  55.     CharStyle *plainStyle;
  56.  
  57.     void MatchBracketForward(int from, int obracket, int cbracket);
  58.     void MatchBracketBackward(int from, int obracket, int cbracket);
  59.     void ExitCursorMode();
  60.     int CursorPos(int ch, int line, EvtCursorDir d, Point);
  61.     void SetupStyles(Font *fp);
  62.     
  63. };
  64.  
  65. //---- CodeAnalyzer --------------------------------------------------------
  66.  
  67. class CodeAnalyzer {
  68.     bool inDefine;
  69.     int lastComment, prevCh, c; 
  70.     int braceStack, inString, escape, inClass, line;
  71.     int canBeClas, canBeFunction;
  72.  
  73.     void FoundComment(AutoTextIter *next);
  74.     void FoundEndOfLineComment(AutoTextIter *next);
  75.     void FoundFunctionOrMethod(int at, int lastComment);
  76.     void FoundClassDecl(int at);
  77.     bool IsClassDecl(int at);
  78.     
  79. protected:
  80.     Text *text;
  81.  
  82.     virtual void Start();
  83.     virtual void Comment(int line, int start, int end);
  84.     virtual void ClassDecl(int line, int start, int end, char *name);
  85.     virtual void Function(
  86.     int line, int start, int end, char *name, char *classname
  87.     );
  88.     virtual void End();
  89.  
  90. public:
  91.     CodeAnalyzer(Text *t);
  92.     void Doit();
  93. };
  94.  
  95. //---- PrettyPrinter --------------------------------------------------------
  96.  
  97. class PrettyPrinter: public CodeAnalyzer {
  98.     class StyledText *stext;
  99.     class RunArray *st;
  100.     CharStyle *commentStyle;
  101.     CharStyle *functionStyle;
  102.     CharStyle *classDeclStyle;
  103.     CharStyle *plainStyle;
  104. protected:
  105.     void Start();
  106.     void Comment(int line, int start, int end);
  107.     void ClassDecl(int line, int start, int end, char *name);
  108.     void Function(int line, int start, int end, char *name, char *classname);
  109.     void End();
  110. public:
  111.     PrettyPrinter(
  112.     Text *t, CharStyle *cs, CharStyle *fs, CharStyle *cds, CharStyle *ps
  113.     );
  114. };
  115.  
  116. #endif  
  117.